﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using com.fukefu.source;

namespace com.fukefu.spider
{
    public class SogouSpider : Spider
    {
        Source source = new Source();

        public int GetShoulu(string url)
        {
            throw new NotImplementedException();
        }

        public int GetShoulu(string url, int days)
        {
            throw new NotImplementedException();
        }

        public bool CheckShoulu(string url)
        {
            throw new NotImplementedException();
        }

        public string GetHtml(string keyword)
        {
            return GetHtml(keyword, 10);
        }

        public string GetHtml(string keyword, int resultLength)
        {
            return GetHtml(keyword, resultLength, 0);
        }

        public string GetHtml(string keyword, int resultLength, int days)
        {
            return source.Get("http://www.sogou.com/web?query=" + MyFunction.EncodeByGb2312(keyword) + "&num=" + resultLength, "http://www.sogou.com");
        }

        public List<string> GetXgKeyword(string keyword)
        {
            string html = GetHtml(keyword);
            List<string> list = new List<string>();
            MatchCollection mc = Regex.Matches(html, "<td><a[^>]+>(.+?)</a></td>");
            foreach (Match m in mc)
            {
                list.Add(m.Groups[1].Value);
            }
            return list;
        }
    }
}
